<?php

namespace App\Models\Vote;

use Illuminate\Database\Eloquent\Model;

/**
 * Class ExportVoteSubject
 * @property  views
 * @package App\Models\Vote\ExportVoteSubject
 */
class ExportVoteSubject extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'export_vote_subjects';

    public function setChoicesAttribute($choices)
    {
        $this->attributes['choices'] = json_encode($choices);
    }

    public function getChoicesAttribute()
    {
        return json_decode($this->attributes['choices']);
    }

    public function copy($voteSubject)
    {
        $this->created_at = $voteSubject->created_at;
        $this->id = $voteSubject->id;
        $this->user_id = $voteSubject->user_id;
        $this->title = $voteSubject->title;
        $this->sense_id = $voteSubject->sense_id;
        $this->my_choice = $voteSubject->my_choice;
        $this->choices = $voteSubject->choices;
        $this->source_id = $voteSubject->id;
        $this->views = $voteSubject->views;
        $this->likes = $voteSubject->likes;
        $this->total = $voteSubject->total;
    }

    public static function makeFromVoteSubject($voteSubject)
    {
        $exportObj = new ExportVoteSubject;
        $exportObj->copy($voteSubject);
        return $exportObj;
    }

}